<template>
    <h2>注册</h2>
    <table>
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" v-model="info.Uname">
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="password" v-model="info.Upwd">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="AddUser">注册</button>
        </td>
    </tr>
    </table>
</template>

<script setup lang="ts">
import { ref } from "vue"
import axios from "axios"
import { useRouter } from "vue-router"

const router = useRouter()

const info = ref({
    Uname: "",
    Upwd: "",
})



const AddUser = () => {
    axios.post("http://localhost:53393/api/User/AddUser", info.value).then((res) => {
        if (res.data>0) {
            alert("注册成功")
            router.push("/Login")
        } 
        else if(res.data==-1)
        {
            alert("用户名已存在")
        }
        else 
        {
            alert(res.data.msg)
        }
    })
}



</script>